#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
using namespace std;

class Solution {
public:
    vector<int> smallestK(vector<int>& arr, int k) {
        srand(time(0));
        sort(0, arr.size() - 1, k, arr);
        return { arr.begin(),arr.begin() + k };
    }

    void sort(int l, int r, int k, vector<int>& arr)
    {
        if (l >= r) return;
        int key = arr[getRandom(l, r)];
        int left = l - 1, right = r + 1, i = l;
        while (i < right)
        {
            if (arr[i] < key) swap(arr[i++], arr[++left]);
            else if (arr[i] == key) i++;
            else swap(arr[--right], arr[i]);
        }
        int a = left - l + 1, b = right - 1 - (left + 1) + 1;
        if (k <= a) sort(l, left, k, arr);
        else if (k <= a + b) return;
        else sort(right, r, k - a - b, arr);
    }

    int getRandom(int left, int right)
    {
        return  rand() % (right - left + 1) + left;
    }
};

int main() {
    return 0;
}